#coding=utf-8
#@Time:2019/12/11 6:33 PM
#@Author:希哥
#@File:mysql.py

import mysql.connector

'''
    测试本地数据库
'''
def mysql_connect():
    # MySQL相关设置
    mysql_host = '192.168.0.169'
    mysql_user = 'root'
    mysql_passwd = 'root'
    mysql_port = '3306'
    mysql_database = 'hupo'

    #连接数据库
    try:
        connect = mysql.connector.connect(host=mysql_host,user=mysql_user,password=mysql_passwd,db=mysql_database,port=mysql_port,charset="utf8")
        cursor = connect.cursor(buffered=True)
        return connect, cursor
    except:
        print u"Message:连接数据库失败"

'''
    琥珀测试环境数据库
'''
def mysql_connect_hupotest():
    # MySQL相关设置
    mysql_host = 'dev.hupovip.cn'
    mysql_user = 'root'
    mysql_passwd = 'MHp9312Zz'
    mysql_port = '3306'
    mysql_database = 'hp_mall1017'

    #连接数据库
    try:
        connect = mysql.connector.connect(host=mysql_host,user=mysql_user,password=mysql_passwd,db=mysql_database,port=mysql_port,charset="utf8")
        cursor = connect.cursor(buffered=True)
        return connect, cursor
    except:
        print u"Message:连接数据库失败"


'''
    琥珀线上环境数据库
'''
def mysql_connect_hupomallnew():
    # MySQL相关设置
    mysql_host = 'hp-extranet.mysql.rds.aliyuncs.com'
    mysql_user = 'hupovip'
    mysql_passwd = '30ae7ebf859cc82d2a697BCea23466a6'
    mysql_port = '3306'
    mysql_database = 'hp_mall_new'

    #连接数据库
    try:
        connect = mysql.connector.connect(host=mysql_host,user=mysql_user,password=mysql_passwd,db=mysql_database,port=mysql_port,charset="utf8")
        cursor = connect.cursor(buffered=True)
        return connect, cursor
    except:
        print u"Message:连接数据库失败"

if __name__=='__main__':
    mysql_connect_hupotest()